package com.pig4cloud.pig.mt.manage;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.mt.entity.WxTemplateMsgLog;
import com.pig4cloud.pig.mt.service.WxTemplateMsgLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 模版消息发送记录
 *
 * @author niefy
 * @email niefy@qq.com
 * @date 2019-11-12 18:30:15
 */
@RestController
@RequestMapping("/manage/templateMsgLog")
@Api(value = "/manage/templateMsgLog", tags = "微信模版消息发送记录管理")
public class TemplateMsgLogManageController {
    @Autowired
    private WxTemplateMsgLogService templateMsgLogService;
    @Autowired
    private WxMpService wxMpService;

    /**
     * 列表
     */
	@ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/list")
	@PreAuthorize("@pms.hasPermission('mt_wxtemplatemsglog_get')" )
    public R list(@CookieValue String appid, @RequestParam Map<String, Object> params) {
        params.put("appid",appid);
        IPage page = templateMsgLogService.queryPage(params);

        return R.ok(page);
    }


    /**
     * 信息
     */
	@ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/info/{logId}")
	@PreAuthorize("@pms.hasPermission('mt_wxtemplatemsglog_get')" )
    public R info(@CookieValue String appid, @PathVariable("logId") Integer logId) {
        WxTemplateMsgLog templateMsgLog = templateMsgLogService.getById(logId);

        return R.ok(templateMsgLog);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
	@ApiOperation(value = "新增微信模版消息发送记录", notes = "新增微信模版消息发送记录")
	@SysLog("新增微信模版消息发送记录" )
	@PreAuthorize("@pms.hasPermission('mt_wxtemplatemsglog_add')" )
    public R save(@CookieValue String appid, @RequestBody WxTemplateMsgLog templateMsgLog) {
        templateMsgLogService.save(templateMsgLog);

        return R.ok();
    }

    /**
     * 修改
     */
	@ApiOperation(value = "修改微信模版消息发送记录", notes = "修改微信模版消息发送记录")
	@SysLog("修改微信模版消息发送记录" )
    @PutMapping("/update")
	@PreAuthorize("@pms.hasPermission('mt_wxtemplatemsglog_edit')" )
    public R update(@CookieValue String appid, @RequestBody WxTemplateMsgLog templateMsgLog) {
        templateMsgLogService.updateById(templateMsgLog);

        return R.ok();
    }

    /**
     * 删除
     */
	@ApiOperation(value = "通过id删除微信模版消息发送记录", notes = "通过id删除微信模版消息发送记录")
	@SysLog("通过id删除微信模版消息发送记录" )
    @DeleteMapping("/delete")
	@PreAuthorize("@pms.hasPermission('mt_wxtemplatemsglog_del')" )
    public R delete(@CookieValue String appid, @RequestBody Integer[] logIds) {
        templateMsgLogService.removeByIds(Arrays.asList(logIds));

        return R.ok();
    }

}
